// Copyright (c) 2024, lanlian and contributors
// For license information, please see license.txt

frappe.ui.form.on("EMS Fault Repair Task", {
	refresh(frm) {
        // 故障报修派工下推故障维修
        frm.add_custom_button(__('Make EMS Fault Repair'), () => {
            frappe.model.open_mapped_doc({
                method: "ems.equipment_managerment_system.doctype.ems_fault_repair_task.ems_fault_repair_task.make_fault_repair",
                frm: cur_frm,
                freeze_message: __("Creating Task ...")
            });
        });
	},
    intelligent_allocation:function(frm) {
        if (frm.doc.responsible_person) {frappe.msgprint('已分配!')}
        else{
            frappe.msgprint({
                title: __('智能分配规则'),
                message: __('经验优先者*无, 设备责任人*蓝工, 指定责任人*无'),
                primary_action:{
                    action(values) {
                        frappe.db.get_value('EMS Equipment Card', frm.doc.equipment_number, 'responsible_person')
                        .then(r => {frm.set_value('repair_man', r.message.responsible_person); frm.refresh_field('responsible_person')})
                    }
                }
            });
        }

    },
});
